package cn.minds.capture.dispatch;

import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class CaputureOutputStream extends FilterOutputStream {

	protected Object lock = new Object();

	public CaputureOutputStream(OutputStream out) {
		super(out);
	}

	public boolean write(String message) throws IOException {
		synchronized (lock) {
			out.write(message.getBytes());
			out.write('\n');
			out.write('\r');
		}
		return true;
	}

	public void close() {
		synchronized (lock) {
			try {
				out.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

}
